package com.treasure.mall.biz.entity.user;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;

/**
 * 
 *  * 人物关系冗余实体
 *  * 无论距离多远都会被保存
 * +---------------------------------------------------------
 * * @package: com.treasure.mall.biz.entity.user
 * * @author: guomw (guomwchen@foxmail.com)
 * * @date: 2020/6/11 13:49
 * * @since: V1.0.0
 * +---------------------------------------------------------
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
 * Copyright 2019-2022 com.treasure.mall.biz.entity.user Inc. All rights reserved.
 */
@Entity
@Getter
@Setter
@Table(name = "zb_user_relax")
@NoArgsConstructor
public class UserRelax {

    /**
     * 自增id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 级别深度
     */
    @Column(name = "depth", length = 10)
    private Integer depth;

    /**
     * 父id(祖先)
     */
    @ManyToOne
    @JoinColumn(name = "parent_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
    private UserPO parent;

    /**
     * 子id(子孙)
     */
    @Column(name = "child_id", length = 10)
    private Long childId;

    public UserRelax(Integer depth, Long parentId, Long childId) {
        UserPO parent= new UserPO();
        parent.setUserId(parentId);
        this.depth = depth;
        this.parent = parent;
        this.childId = childId;
    }
}
